package com.friends.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Zhao Tianhao
 * @version 2023/07/07 16:20
 **/
@Slf4j
public class ResponseUtil {
    public static void responseFailMessage(HttpServletResponse response, Integer status, String msg) {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        Map<String, Object> map = new HashMap<>();
        map.put("code", status);
        map.put("msg", msg);
        try {
            response.getWriter().println(JSON.toJSONString(map));
        } catch (IOException e) {
            log.error("发送消息到客户端失败", e);
        }
    }
}